class FindSumPairs
{
public:
    FindSumPairs(vector<int> &nums1, vector<int> &nums2)
    {
        for (int num : nums1)
        {
            ++nums1Count[num];
        }
        for (int num : nums2)
        {
            ++nums2Count[num];
        }
        _nums2 = nums2;
    }

    void add(int index, int val)
    {
        --nums2Count[_nums2[index]];
        _nums2[index] += val;
        ++nums2Count[_nums2[index]];
    }

    int count(int tot)
    {
        int result = 0;
        for (auto &[num, count] : nums1Count)
        {
            if (nums2Count.count(tot - num))
            {
                result += count * nums2Count[tot - num];
            }
        }
        return result;
    }

private:
    vector<int> _nums2;
    unordered_map<int, int> nums1Count;
    unordered_map<int, int> nums2Count;
};

/**
 * Your FindSumPairs object will be instantiated and called as such:
 * FindSumPairs* obj = new FindSumPairs(nums1, nums2);
 * obj->add(index,val);
 * int param_2 = obj->count(tot);
 */